import pyecharts.options as opts
from pyecharts.charts import Sankey

topic_201901 = '数学微分方程'
topic_201902 = '交通拓扑规划'
topic_201903 = '组合设计理论'
topic_201904 = '文化传播周期'

topic_201801 = '微分方程 '
topic_201802 = '学校暑期'
topic_201803 = '非线性模型函数'
topic_201804 = '数学方法整数分解'

topic_201701 = '数学非线性模型 '
topic_201702 = '空间几何结构优化'
topic_201703 = '随机代数理论'
topic_201704 = '量子图像算子'

topic_201601 = '量子方法方程 '
topic_201602 = '动力学方法'
topic_201603 = '材料分析'
topic_201604 = '系统效应'

topic_201501 = '纳米材料分子 '
topic_201502 = '结构方法'
topic_201503 = '动力学控制力学'
topic_201504 = '激光辐射'


topic_201401 = '系统耦合分析 '
topic_201402 = '等离子体材料'
topic_201403 = '量子结构动力学方法'
topic_201404 = '纳米分子电子'

topic_201301 = '自旋理论模型 '
topic_201302 = '量子结构方程'
topic_201303 = '电子空间理论'
topic_201304 = '非线性材料'

node = [
    {'name': '2019主题'},
    {'name': topic_201901}, {'name': topic_201902}, {'name': topic_201903}, {'name': topic_201904},

    {'name': '2018主题'},
    {'name': topic_201801}, {'name': topic_201802}, {'name': topic_201803}, {'name': topic_201804},

    {'name': '2017主题'},
    {'name': topic_201701}, {'name': topic_201702}, {'name': topic_201703}, {'name': topic_201704},

    {'name': '2016主题'},
    {'name': topic_201601}, {'name': topic_201602}, {'name': topic_201603}, {'name': topic_201604},

    {'name': '2015主题'},
    {'name': topic_201501}, {'name': topic_201502}, {'name': topic_201503}, {'name': topic_201504},

    {'name': '2014主题'},
    {'name': topic_201401}, {'name': topic_201402}, {'name': topic_201403}, {'name': topic_201404},

    {'name': '2013主题'},
    {'name': topic_201301}, {'name': topic_201302}, {'name': topic_201303}, {'name': topic_201304},

]  # 此处罗列各分支名称，后面的数字代表具体的量值(注：因为pyecharts无法直接显示value，所以需要这样标注)。
link = [
    {'source': '2019主题', 'target': topic_201901, 'value': 1.1},
    {'source': topic_201901, 'target': topic_201902, 'value': 1.1},
    {'source': topic_201902, 'target': topic_201903, 'value': 1.1},
    {'source': topic_201903, 'target': topic_201904, 'value': 1.1},

    {'source': '2018主题', 'target': topic_201801, 'value': 1.2},
    {'source': topic_201801, 'target': topic_201802, 'value': 1.2},
    {'source': topic_201802, 'target': topic_201803, 'value': 1.2},
    {'source': topic_201803, 'target': topic_201804, 'value': 1.2},

    {'source': '2017主题', 'target': topic_201701, 'value': 1.3},
    {'source': topic_201701, 'target': topic_201702, 'value': 1.3},
    {'source': topic_201702, 'target': topic_201703, 'value': 1.3},
    {'source': topic_201703, 'target': topic_201704, 'value': 1.3},

    {'source': '2016主题', 'target': topic_201601, 'value': 1.4},
    {'source': topic_201601, 'target': topic_201602, 'value': 1.4},
    {'source': topic_201602, 'target': topic_201603, 'value': 1.4},
    {'source': topic_201603, 'target': topic_201604, 'value': 1.4},

    {'source': '2015主题', 'target': topic_201501, 'value': 1.5},
    {'source': topic_201501, 'target': topic_201502, 'value': 1.5},
    {'source': topic_201502, 'target': topic_201503, 'value': 1.5},
    {'source': topic_201503, 'target': topic_201504, 'value': 1.5},

    {'source': '2014主题', 'target': topic_201401, 'value': 1.6},
    {'source': topic_201401, 'target': topic_201402, 'value': 1.6},
    {'source': topic_201402, 'target': topic_201403, 'value': 1.6},
    {'source': topic_201403, 'target': topic_201404, 'value': 1.6},

    {'source': '2013主题', 'target': topic_201301, 'value': 1.7},
    {'source': topic_201301, 'target': topic_201302, 'value': 1.7},
    {'source': topic_201302, 'target': topic_201303, 'value': 1.7},
    {'source': topic_201303, 'target': topic_201304, 'value': 1.7},

]

pic_topic = (
    Sankey().add('',
                 node,
                 link,
                 linestyle_opt=opts.LineStyleOpts(opacity=0.3, curve=0.5, color='source'),
                 label_opts=opts.LabelOpts(position='right'),
                 node_gap=30,  # 节点之间的距离,(查看垂直图片的操作orient="vertical")

                 ).set_global_opts(title_opts=opts.TitleOpts(title='各年份主题'))
)

pic_topic.render('11_桑基图-平行图.html')